﻿namespace ExamV5.ZiExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public class FrmSetStand : Page
    {
        protected Button butAdd;
        protected GridView DataGridInfo;
        protected DropDownList DDLGWName;
        protected HtmlForm Form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        protected Label labRescordCount;
        protected LinkButton LBDel;
        protected LinkButton LBFirstPage;
        protected LinkButton LBLastPage;
        protected LinkButton LBNextPage;
        protected LinkButton LBPrevPage;
        protected LinkButton LBSelect;
        private PublicFun publicFun_0 = new PublicFun();
        protected ScriptManager SM;
        protected TextBox txtAgeEnd;
        protected TextBox txtAgeStart;
        protected TextBox txtLevelName;
        protected TextBox txtPassNum;
        protected UpdatePanel UPPart;

        protected AspNetPager aspPager;
        protected void butAdd_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) == 0x3a)
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTHB", "alert('该版本为特惠版，此功能未开放！')", true);
            }
            else
            {
                string strSql = "insert into ZiStandInfo(Worker,AgeStart,AgeEnd,LevelName,PassNum) values('" + this.DDLGWName.SelectedItem.Text.Trim() + "'," + this.txtAgeStart.Text.Trim() + "," + this.txtAgeEnd.Text.Trim() + ",'" + this.txtLevelName.Text.Trim() + "'," + this.txtPassNum.Text.Trim() + ")";
                this.publicFun_0.ExecuteSql(strSql);
                this.method_0();
                this.txtAgeStart.Text = "";
                this.txtAgeEnd.Text = "";
                this.txtLevelName.Text = "";
                this.txtPassNum.Text = "";
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DataGridInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.DataGridInfo.PageIndex = e.NewPageIndex;
            this.method_0();
        }

        protected void DataGridInfo_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            this.DataGridInfo.EditIndex = -1;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DataGridInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //if (e.Row.DataItemIndex != -1)
            //{
            //    e.Row.Attributes.Add("onmouseover", "this.bgColor='#F6F5F5'");
            //    if ((e.Row.DataItemIndex % 2) != 0)
            //    {
            //        e.Row.Attributes.Add("bgcolor", "#FFFFFF");
            //        e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('oldValue')");
            //    }
            //    else
            //    {
            //        e.Row.Attributes.Add("bgcolor", "#FFFFFF");
            //        e.Row.Attributes.Add("onmouseout", "this.bgColor=document.getElementById('DataGridInfo').getAttribute('singleValue')");
            //    }
            //}
            //else
            //{
            //    this.DataGridInfo.Attributes.Add("oldValue", "#FFFFFF");
            //    this.DataGridInfo.Attributes.Add("singleValue", "#FFFFFF");
            //}
            if ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)))
            {
                DropDownList list = (DropDownList) e.Row.Cells[0].FindControl("DDLGridType");
                list.DataTextField = "ParmName";
                list.DataValueField = "ParmValue";
                list.DataSource = this.publicFun_0.RetrunDataView("select ParmName,ParmValue from SysParmInfo where ParmMemo='GWName'");
                list.DataBind();
                list.SelectedIndex = -1;
                list.Items.FindByText(this.DataGridInfo.DataKeys[e.Row.RowIndex]["Worker"].ToString()).Selected = true;
                TextBox box = (TextBox) e.Row.Cells[2].Controls[0];
                TextBox box2 = (TextBox) e.Row.Cells[3].Controls[0];
                TextBox box3 = (TextBox) e.Row.Cells[4].Controls[0];
                TextBox box4 = (TextBox) e.Row.Cells[5].Controls[0];
                box.CssClass = "text";
                box2.CssClass = "text";
                box3.CssClass = "text";
                box4.CssClass = "text";
                box.MaxLength = 3;
                box2.MaxLength = 3;
                box.Width = 50;
                box2.Width = 50;
                box3.Width = 100;
                box4.Width = 50;
                box.Attributes.Add("onpaste", " return false");
                box.Attributes.Add("style", " IME-MODE: disabled");
                box.Attributes.Add("onkeypress", " javascript:if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;");
                box2.Attributes.Add("onpaste", " return false");
                box2.Attributes.Add("style", " IME-MODE: disabled");
                box2.Attributes.Add("onkeypress", " javascript:if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;");
                box4.Attributes.Add("onpaste", " return false");
                box4.Attributes.Add("style", " IME-MODE: disabled");
                box4.Attributes.Add("onkeypress", " javascript:if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;");
            }
            if (e.Row.RowType == DataControlRowType.Header)
            {
                if (!(this.ViewState["SortType"].ToString() == " Desc"))
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "Worker":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "AgeStart":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "AgeEnd":
                            e.Row.Cells[3].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "LevelName":
                            e.Row.Cells[4].Controls.Add(new LiteralControl("↓"));
                            return;

                        case "PassNum":
                            e.Row.Cells[5].Controls.Add(new LiteralControl("↓"));
                            return;
                    }
                    e.Row.Cells[1].Controls.Add(new LiteralControl("↓"));
                }
                else
                {
                    switch (this.ViewState["SortFiled"].ToString())
                    {
                        case "Worker":
                            e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "AgeStart":
                            e.Row.Cells[2].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "AgeEnd":
                            e.Row.Cells[3].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "LevelName":
                            e.Row.Cells[4].Controls.Add(new LiteralControl("↑"));
                            return;

                        case "PassNum":
                            e.Row.Cells[5].Controls.Add(new LiteralControl("↑"));
                            return;
                    }
                    e.Row.Cells[1].Controls.Add(new LiteralControl("↑"));
                }
            }
        }

        protected void DataGridInfo_RowEditing(object sender, GridViewEditEventArgs e)
        {
            this.DataGridInfo.EditIndex = e.NewEditIndex;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DataGridInfo_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            try
            {
                string str = this.DataGridInfo.DataKeys[e.RowIndex]["ID"].ToString();
                DropDownList list = (DropDownList)this.DataGridInfo.Rows[e.RowIndex].Cells[0].FindControl("DDLGridType");
                TextBox box = (TextBox)this.DataGridInfo.Rows[e.RowIndex].Cells[2].Controls[0];
                TextBox box2 = (TextBox)this.DataGridInfo.Rows[e.RowIndex].Cells[3].Controls[0];
                TextBox box3 = (TextBox)this.DataGridInfo.Rows[e.RowIndex].Cells[4].Controls[0];
                TextBox box4 = (TextBox)this.DataGridInfo.Rows[e.RowIndex].Cells[5].Controls[0];
                box.CssClass = "text";
                box2.CssClass = "text";
                box3.CssClass = "text";
                box4.CssClass = "text";
                box.MaxLength = 3;
                box2.MaxLength = 3;
                box.Width = 50;
                box2.Width = 50;
                box3.Width = 100;
                box4.Width = 50;
                box.Attributes.Add("onpaste", " return false");
                box.Attributes.Add("style", " IME-MODE: disabled");
                box.Attributes.Add("onkeypress", " javascript:if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;");
                box2.Attributes.Add("onpaste", " return false");
                box2.Attributes.Add("style", " IME-MODE: disabled");
                box2.Attributes.Add("onkeypress", " javascript:if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;");
                box4.Attributes.Add("onpaste", " return false");
                box4.Attributes.Add("style", " IME-MODE: disabled");
                box4.Attributes.Add("onkeypress", " javascript:if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false;");
                if (list.SelectedItem.Text.Trim() == "")
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckA", "alert('请选择岗位名称！')", true);
                }
                else if (box.Text.Trim() == "")
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckB", "alert('请输入起始年龄！')", true);
                }
                else if (box2.Text.Trim() != "")
                {
                    if (Convert.ToInt16(box.Text.Trim()) <= Convert.ToInt16(box2.Text.Trim()))
                    {
                        if (box3.Text.Trim() != "")
                        {
                            if (!(box4.Text.Trim() == ""))
                            {
                                this.publicFun_0.ExecuteSql("update ZiStandInfo set Worker='" + list.SelectedItem.Text.Trim() + "',AgeStart=" + box.Text.Trim() + ",AgeEnd=" + box2.Text.Trim() + ",LevelName='" + box3.Text.Trim() + "',PassNum=" + box4.Text.Trim() + " where ID=" + str);
                                this.DataGridInfo.EditIndex = -1;
                                this.method_0();
                            }
                            else
                            {
                                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckF", "alert('请输入通字字数！')", true);
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckE", "alert('请输入级别名称！')", true);
                        }
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckD", "alert('起始年龄不能大于终止年龄！')", true);
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheckC", "alert('请输入终止年龄！')", true);
                }
            }
            catch
            {
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
            }
        }

        protected void DataGridInfo_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sortExpression = e.SortExpression;
            if (!(this.ViewState["SortFiled"].ToString() == sortExpression))
            {
                this.ViewState["SortFiled"] = e.SortExpression;
            }
            else if (!(this.ViewState["SortType"].ToString() == " Desc"))
            {
                this.ViewState["SortType"] = " Desc";
            }
            else
            {
                this.ViewState["SortType"] = " ASC";
            }
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void DataGridInfo_PreRender(object sender, EventArgs e)
        {
            // 使用<TH>替换<TD> 
            this.DataGridInfo.UseAccessibleHeader = true;
            //HeaderRow将被<thead>包裹，数据行将被<tbody>包裹
            this.DataGridInfo.HeaderRow.TableSection = TableRowSection.TableHeader;
        }

        protected void aspPager_PageChanged(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = this.aspPager.CurrentPageIndex - 1;
            this.method_0();
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void LBDel_Click(object sender, EventArgs e)
        {
            int num = 0;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = null;
            for (int i = 0; i < this.DataGridInfo.Rows.Count; i++)
            {
                CheckBox box = (CheckBox) this.DataGridInfo.Rows[i].FindControl("CheckBoxSelect");
                if (box.Checked)
                {
                    num++;
                    command = new SqlCommand("delete  from ZiStandInfo where ID='" + this.DataGridInfo.DataKeys[i]["ID"].ToString() + "';insert into SysLogInfo(LogDisp,EditUser,EditUserCode) values('删除打字考核标准信息！','" + this.httpCookie_1.Value + "','" + this.httpCookie_0.Value + "')", connection);
                    command.ExecuteNonQuery();
                    command.Dispose();
                }
            }
            connection.Close();
            connection.Dispose();
            if (this.DataGridInfo.Rows.Count == num)
            {
                this.DataGridInfo.PageIndex = 0;
            }
            this.method_0();
            this.LBSelect.Text = "选中当页";
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        protected void LBFirstPage_Click(object sender, EventArgs e)
        {
            this.DataGridInfo.PageIndex = 0;
            this.method_0();
        }

        protected void LBLastPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageCount > 0)
            {
                this.DataGridInfo.PageIndex = this.DataGridInfo.PageCount - 1;
                this.method_0();
            }
        }

        protected void LBNextPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex < (this.DataGridInfo.PageCount - 1))
            {
                this.DataGridInfo.PageIndex++;
                this.method_0();
            }
        }

        protected void LBPrevPage_Click(object sender, EventArgs e)
        {
            if (this.DataGridInfo.PageIndex > 0)
            {
                this.DataGridInfo.PageIndex--;
                this.method_0();
            }
        }

        protected void LBSelect_Click(object sender, EventArgs e)
        {
            int num;
            CheckBox box;
            if (this.LBSelect.Text != "选中当页")
            {
                for (num = 0; num < this.DataGridInfo.Rows.Count; num++)
                {
                    box = (CheckBox) this.DataGridInfo.Rows[num].FindControl("CheckBoxSelect");
                    box.Checked = false;
                }
                this.LBSelect.Text = "选中当页";
            }
            else
            {
                for (num = 0; num < this.DataGridInfo.Rows.Count; num++)
                {
                    box = (CheckBox) this.DataGridInfo.Rows[num].FindControl("CheckBoxSelect");
                    if (box.Enabled)
                    {
                        box.Checked = true;
                    }
                }
                this.LBSelect.Text = "取消所选";
            }
            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "Render", "LayaUIFormRender();", true);
        }

        private void method_0()
        {
            string selectCommandText = "";
            if (!(this.ViewState["Power"].ToString() == "Y"))
            {
                selectCommandText = "select * from ZiStandInfo where ID=0";
                ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BPower", "alert('打字参数设置权限未开放！')", true);
            }
            else
            {
                selectCommandText = "select * from ZiStandInfo where ID<>0";
            }
            selectCommandText = selectCommandText + " order by " + this.ViewState["SortFiled"].ToString() + this.ViewState["SortType"].ToString();
            SqlConnection selectConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "DataInfo");
            this.DataGridInfo.DataSource = dataSet.Tables["DataInfo"].DefaultView;
            this.DataGridInfo.DataBind();
            //this.labRescordCount.Text = "总共&nbsp;<font color='#0000C0'><b>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</b></font>&nbsp;条记录&nbsp;<font color='#0000C0'><b>" + Convert.ToString((int) (this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b></font>&nbsp;页&nbsp;";
            this.labRescordCount.Text = "总共&nbsp;<i>" + dataSet.Tables["DataInfo"].Rows.Count.ToString() + "</i>&nbsp;条记录&nbsp;<b>" + Convert.ToString((int)(this.DataGridInfo.PageIndex + 1)) + "/" + this.DataGridInfo.PageCount.ToString() + "</b>&nbsp;页&nbsp;";
            this.aspPager.RecordCount = dataSet.Tables["DataInfo"].Rows.Count;
            adapter.Dispose();
            selectConnection.Close();
            selectConnection.Dispose();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) && (this.httpCookie_0.Value != ""))
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                if (Convert.ToInt32(ConfigurationManager.ConnectionStrings["OnlineNum"].ConnectionString) != 0x3a)
                {
                    if (!base.IsPostBack)
                    {
                        if (this.publicFun_0.ReturnPaperData() != "Yes")
                        {
                            ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BCheck", "alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')", true);
                        }
                        else
                        {
                            this.ViewState["Power"] = this.publicFun_0.GetValues("select ZiManag from UserPower where UserCode='" + this.httpCookie_0.Value + "'", "ZiManag");
                            this.ViewState["SortFiled"] = "ID";
                            this.ViewState["SortType"] = " Desc";
                            this.DDLGWName.DataTextField = "ParmName";
                            this.DDLGWName.DataValueField = "ParmValue";
                            this.DDLGWName.DataSource = this.publicFun_0.RetrunDataView("select ParmName,ParmValue from SysParmInfo where ParmMemo='GWName'");
                            this.DDLGWName.DataBind();
                            ListItem item = new ListItem("--请选择--", "");
                            this.DDLGWName.Items.Add(item);
                            this.DDLGWName.Items.FindByValue("").Selected = true;
                            this.LBDel.Attributes.Add("onclick", "javascript:{if(confirm('确定删除所有选中考核标准信息吗？')==false) return false;}");
                            this.method_0();
                        }
                    }
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this.UPPart, this.Page.GetType(), "BTHB", "alert('该版本为特惠版，此功能未开放！')", true);
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

